A = [1, 2, 3, 2, 1]
B = [3, 2, 1, 4, 7]
# 给两个整数数组 A 和 B ，返回两个数组中公共的、长度最长的子数组的长度。

n = len(A)
m = len(B)
result = 0
dp = [[0] * (m + 1) for _ in range(n + 1)]

for i in range(n - 1, -1, -1):
    for j in range(m - 1, -1, -1):
        if A[i] == B[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        else:
            dp[i][j] = 0
        result = max(result, dp[i][j])
print(result)
